'----------------------------------------------
' Name: Ali Karbassi & Mike Raasch
' Date: April 10, 2007
' Description: Project 6
'              Form frmQuiz
'----------------------------------------------
Imports UWPCS3340

Public Class frmQuiz

   Dim q As UWPCS3340.IQuestion = Nothing

   ''' <summary>
   ''' Goes back to the start form.
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
               Handles btnBack.Click, btnback2.Click

      Me.Hide()
      frmStart.Show()

   End Sub

   ''' <summary>
   ''' Display all the questions.
   ''' </summary>
   ''' <remarks></remarks>
   Public Sub showList()

      Dim x As Integer
      Dim y As Integer = lblThankYou.Bottom

      Me.SuspendLayout()

      For index As Integer = 0 To questions.Count - 1
         q = questions(index)

         x = (Me.ClientSize.Width / 2) - (q.width / 2)

         q.Display(New Point(x, y), Me, UWPCS3340.QuestionMode.Taking)

         y += q.height

      Next
      Me.ResumeLayout()


      Dim spacing As Integer = btnSubmit.Location.Y

      If y = lblThankYou.Bottom Then
         btnSubmit2.Top = Me.ClientSize.Height - btnSubmit2.Height - (2 * spacing)
         btnback2.Top = btnSubmit2.Top
      Else
         btnSubmit2.Top = y
         btnback2.Top = btnSubmit2.Top
      End If

      Me.Top = (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height / 2) - (Me.Height / 2)

   End Sub

   ''' <summary>
   ''' Make sure the program is closed properly.
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub frmQuiz_FormClosing(ByVal sender As System.Object, _
               ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

      If e.CloseReason = CloseReason.UserClosing Then
         Application.Exit()
         End
      End If

   End Sub

   ''' <summary>
   ''' Corrects the quiz and shows the score.
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="e"></param>
   ''' <remarks></remarks>
   Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
               Handles btnSubmit.Click, btnSubmit2.Click

      Dim score As Integer = 0

      For index As Integer = 0 To questions.Count - 1
         score += CType(questions(index), IQuestion).Score
      Next

      MsgBox("Your score is: " & score & ".", MsgBoxStyle.OkOnly, "Prog6")

   End Sub

End Class